package com.decent.ejfadmin.finance.dao.provider;


import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.common.bean.SupAlipay;
import com.decent.ejfadmin.utils.SQLWrapUtils;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;

/**
 * 支付宝配置
 *
 * @author weicx
 * @date 2019/02/25
 */
public class AlipayConfigDaoProvider {

    public String supAlipayCount(HashMap<String, SupAlipay> map) {

        StringBuffer sql = new StringBuffer(100);
        sql.append("SELECT COUNT(1)");
        SupAlipay supAlipay = map.get("supAlipay");
        commonSql(supAlipay, sql);
        return sql.toString();
    }

    private void commonSql(SupAlipay supAlipay, StringBuffer sql) {
        sql.append(" from yuhuang_sup_user u ,yuhuang_sup_alipay sa,yuhuang_sup_info si" +
                "  where sa.user_id = u.user_id and sa.user_id = si.user_id ");
        if (StringUtils.isNotBlank(supAlipay.getAccount())) {
            sql.append("  and (instr(u.account,#{supAlipay.account})>0 or instr(si.name,#{supAlipay.account})>0) ");
        }
        if (StringUtils.isNotBlank(supAlipay.getAlipay())) {
            sql.append("  and instr(sa.alipay,#{supAlipay.alipay})>0 ");
        }
    }

    public String supAlipayDetail(HashMap<String, Object> map) {
        StringBuffer sql = new StringBuffer(100);
        SupAlipay supAlipay = (SupAlipay) map.get("supAlipay");
        Page page = (Page) map.get("page");
        sql.append(" SELECT " +
                " sa.id, " +
                " sa.user_id, " +
                " si.name, " +
                " sa.alipay, " +
                " sa.gmt_create, " +
                " sa.gmt_modified, " +
                " sa.remark, " +
                " sa.is_use, " +
                " u.account ");
        commonSql(supAlipay, sql);
        sql.append(" ORDER BY sa.id desc   ");
        return SQLWrapUtils.wrapPage(sql, page.getBeginIndex(), page.getSize());
    }


}
